package com.hsj.demo.controller;

import com.hsj.demo.entity.ChatHistory;
import com.hsj.demo.service.ChatHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/chatHistory")
public class ChatHistoryController {
    @Autowired
    private ChatHistoryService chatHistoryService;

    @RequestMapping("/findById")
    public ChatHistory findById(Integer id){
        return chatHistoryService.findById(id);
    }

    @RequestMapping("/getHistoryByUser")
    public List<ChatHistory> getHistoryByUser(Integer sourceUserId, Integer targetUserId){
        return chatHistoryService.findByTime(sourceUserId, targetUserId);
    }

    @RequestMapping("/updateIsRead")
    public String updateIsRead(Integer id,Character isRead){
        return chatHistoryService.update(id,isRead);
    }

    @RequestMapping("/updateIsReadList")
    public String updateIsReadList(@RequestBody List<ChatHistory> isReadList){
        return chatHistoryService.updateIsReadList(isReadList);
    }
}
